package com.ui.activity;

import roboguice.inject.InjectView;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.LinearLayout;

import com.core.sdk.core.BaseActivity;
import com.core.sdk.ui.listview.HorizontalListView;
import com.core.sdk.utils.ScreenUtil;
import com.core.sdk.utils.ToastUtil;
import com.ui.R;
import com.ui.adapter.TestAdapter;
import com.ui.model.Test;

public class HorListViewActivity extends BaseActivity implements OnItemClickListener {

	@InjectView(R.id.act_hor_lv_listview)
	HorizontalListView lv;

	@InjectView(R.id.act_hor_lv_gridview)
	GridView gv;

	TestAdapter adapter = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		adapter = new TestAdapter(this);
		for (int i = 100; i <= 110; i++) {
			adapter.addItem(new Test("" + i), null);
		}

		lv.setAdapter(adapter);
		lv.setOnItemClickListener(this);

		gv.setAdapter(adapter);
		gv.setOnItemClickListener(this);
		int count = adapter.getCount();
		int allWidth = ScreenUtil.dip2px(this, count * 110);
		int itemWidth = ScreenUtil.dip2px(this, 100);
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(allWidth, LinearLayout.LayoutParams.FILL_PARENT);
		gv.setLayoutParams(params);
		gv.setColumnWidth(itemWidth);
		gv.setHorizontalSpacing(2);
		gv.setStretchMode(GridView.NO_STRETCH);
		gv.setNumColumns(count);

		adapter.notifyDataSetChanged();
	}

	@Override
	protected int getContentView() {
		return R.layout.act_hor_lv;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		ToastUtil.show(this, adapter.getItem(position).getData().getText());

	}

}
